package com.quanxiaoha.xiaohashu.oss.biz.service.impl;


import com.quanxiaoha.framework.common.response.Response;
import com.quanxiaoha.xiaohashu.oss.biz.enums.ResponseCodeEnum;
import com.quanxiaoha.xiaohashu.oss.biz.service.FileService;
import com.quanxiaoha.xiaohashu.oss.biz.strategy.FileStrategy;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/**
 * @Author: jingyan_liu
 * @CreateTime: 2025-07-20
 * @Description:
 * @Version: 1.0
 */


@Service
@Slf4j
public class FileServiceImpl implements FileService {
	
	private static final String BUCKET_NAME = "xiaohashu";
	@Resource
	private FileStrategy fileStrategy;
	
	@Override
	public Response<?> uploadFile(MultipartFile file) {
		String url = fileStrategy.uploadFile(file, BUCKET_NAME);
		return Objects.isNull(url) ? Response.fail(ResponseCodeEnum.FILE_UPLOAD_FAILED) : Response.success(url);
	}
}
